package singletonDemo;
//懒汉模式
public class MyObject2 {
    private static MyObject2 myObject2=null;
    private MyObject2(){}
    //加synchronized后为线程安全的

    synchronized public static MyObject2 getInstance(){
        if(myObject2==null){
            myObject2 = new MyObject2();
        }
        return myObject2;
    }
}
